﻿
Namespace LightSwitchApplication

    Public Class PatientPreviousPregnancy
        Private myDialogHelperPreviousPregnancy As ModalWindow
        Private myDialogHelperPreNatalVisit As ModalWindow

        Private Sub PreviousPregnancies_SelectionChanged()
            Me.screenParamPregnancyNo = Nothing
            Me.screenParamPreviousPregnancyNo = Nothing
            If Not Me.PreviousPregnancies.SelectedItem Is Nothing Then
                If Not Me.PreviousPregnancies.SelectedItem.PregnancyNo Is Nothing Then
                    Me.screenParamPregnancyNo = Me.PreviousPregnancies.SelectedItem.PregnancyNo
                Else
                    If Not Me.PreviousPregnancies.SelectedItem.PrevPregnancyNo = Nothing Then
                        Me.screenParamPreviousPregnancyNo = Me.PreviousPregnancies.SelectedItem.PrevPregnancyNo
                    End If
                End If
                Me.FindControl("PrenatalVisit").DisplayName = "PreNatal visits for delivery date " & Me.PreviousPregnancies.SelectedItem.DeliveryDate
            End If

        End Sub

        Private Sub PatientPreviousPregnancy_InitializeDataWorkspace(saveChangesTo As System.Collections.Generic.List(Of Microsoft.LightSwitch.IDataService))
            ' Write your code here.
            If Not paramPatientNo = Nothing Then
                Me.PatientProperty = Me.Patient
                Me.DisplayName = "Pregnancies - " & Me.Patient.SummaryName
            Else
                Me.PatientProperty = New Patient()
            End If


            If Me.Patient.photo Is Nothing Then
                Me.FindControl("photo").IsVisible = False
            End If

            Me.ScreenHeader = "Previous Pregnancy Details"
            myDialogHelperPreNatalVisit = New ModalWindow(Me.PrenatalVisit, "ModalPreviousPregnancyVisits")
            myDialogHelperPreviousPregnancy = New ModalWindow(Me.PreviousPregnancies, "ModalPreviousPregnancy")
        End Sub

        Private Sub PrenatalVisitAddAndEditNew_CanExecute(ByRef result As Boolean)
            ' Write your code here.
            result = myDialogHelperPreNatalVisit.CanAdd
        End Sub

        Private Sub PrenatalVisitAddAndEditNew_Execute()
            ' Write your code here.
            myDialogHelperPreNatalVisit.AddEntity()
        End Sub

        Private Sub OkVisitMethod_Execute()
            ' Write your code here.
            If Not Me.PreviousPregnancies.SelectedItem Is Nothing Then
                If Not Me.PreviousPregnancies.SelectedItem.PregnancyNo Is Nothing Then
                    Me.screenParamPregnancyNo = Me.PreviousPregnancies.SelectedItem.PregnancyNo
                    Me.PrenatalVisit.SelectedItem.PregnancyNo = Me.PreviousPregnancies.SelectedItem.PregnancyNo
                Else
                    If Not Me.PreviousPregnancies.SelectedItem.PrevPregnancyNo = Nothing Then
                        Me.PrenatalVisit.SelectedItem.PreviousPregnancyNo = Me.PreviousPregnancies.SelectedItem.PrevPregnancyNo
                    End If
                End If
            End If
            myDialogHelperPreNatalVisit.DialogOk()
        End Sub

        Private Sub CancelVisitMethod_Execute()
            ' Write your code here.
            myDialogHelperPreNatalVisit.DialogCancel()
        End Sub

        Private Sub PrenatalVisitEditSelected_CanExecute(ByRef result As Boolean)
            ' Write your code here.
            result = myDialogHelperPreNatalVisit.CanView
        End Sub

        Private Sub PrenatalVisitEditSelected_Execute()
            ' Write your code here.
            myDialogHelperPreNatalVisit.ViewEntity()
        End Sub

        Private Sub PatientPreviousPregnancy_Created()
            ' Write your code here.
            myDialogHelperPreNatalVisit.Initialise()
            myDialogHelperPreviousPregnancy.Initialise()
        End Sub

        Private Sub PreviousPregnanciesAddAndEditNew_CanExecute(ByRef result As Boolean)
            ' Write your code here.
            result = myDialogHelperPreviousPregnancy.CanAdd
        End Sub

        Private Sub PreviousPregnanciesAddAndEditNew_Execute()
            ' Write your code here.
            myDialogHelperPreviousPregnancy.AddEntity()
        End Sub

        Private Sub PreviousPregnanciesEditSelected_CanExecute(ByRef result As Boolean)
            ' Write your code here.
            result = myDialogHelperPreviousPregnancy.CanView
        End Sub

        Private Sub PreviousPregnanciesEditSelected_Execute()
            ' Write your code here.
            myDialogHelperPreviousPregnancy.ViewEntity()
        End Sub

        Private Sub OkPreviousPregnancyMethod_Execute()
            ' Write your code here.
            myDialogHelperPreviousPregnancy.DialogOk()
        End Sub

        Private Sub CancelPreviousPregnancyMethod_Execute()
            ' Write your code here.
            myDialogHelperPreviousPregnancy.DialogCancel()
        End Sub
    End Class

End Namespace
